﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Wicresoft.JDPostBoard.Entity;
using Wicresoft.Framework.Organization;
using System.Text;
using Wicresoft.Busi.BizLogic;

public partial class NewMeetingRoom_RoomApplyView1 : BaseNormalPage
{
    #region Property ApplyID
    public int ApplyID
    {
        get
        {
            if (Request["ApplyID"] != null)
                return int.Parse(Request["ApplyID"]);
            else
                return int.MinValue;
        }
    }
    #endregion

    #region Property UserType
    public string UserType
    {
        get
        {
            return Request["UserType"];
        }
    }
    #endregion


    #region Property ApplyStatus
    public string ApplyStatus
    {
        get
        {
            if (ViewState["ApplyStatus"] != null)
                return ViewState["ApplyStatus"].ToString();
            else
                return "";
        }
        set
        {
            ViewState["ApplyStatus"] = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        this.Title = "详细信息";

        if (!IsPostBack)
        {
            loadRoom();
            initMeetingType();
            LoadGoodsInfo();
            LoadApplyInfo();

            
        }
    }

    #region 根据用户初始化会议室下拉框
    private void loadRoom()
    {
        string[] strRoomStatus = new string[] { Wicresoft.Busi.Entity.RoomStatus.OPENED };
        DataTable dt = BLMeetingRooms.GetMeetingRooms(strRoomStatus);
        dt.Columns.Add("RoomDesc", typeof(System.String));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];
            dr["RoomDesc"] = dr[Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + " （座位数：" + dr[Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + "人）";
        }
        this.ddlRoom.DataSource = dt;
        this.ddlRoom.DataTextField = "RoomDesc";
        this.ddlRoom.DataValueField = Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_ID;
        this.ddlRoom.DataBind();
        if (UserType == "Approve" || UserType == "Static")
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--请选择--", "-1"));
        }
        else if (UserType == "view")
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--尚未选择--", "-1"));
        }
        else
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--尚未选择--", "-1"));
        }
    }
    #endregion

    #region 初始化会议室类型
    private void initMeetingType()
    {
        DataTable dt = Wicresoft.Busi.BizLogic.BLDic_MeetingRoom.GetMeetingType();
        this.ddlType.DataSource = dt;
        this.ddlType.DataTextField = Wicresoft.Busi.Entity.Dic_MeetingRoom.SQLCOL_PROPERTYNAME;
        this.ddlType.DataValueField = Wicresoft.Busi.Entity.Dic_MeetingRoom.SQLCOL_PROPERTYID;
        this.ddlType.DataBind();
    }
    #endregion

    #region 会场要求
    private void LoadGoodsInfo()
    {
        DataTable dt = new DataTable();
        if (this.ApplyID == int.MinValue)
        {
            dt = Wicresoft.Busi.BizLogic.BLMeetingRoomGoods.GetMeetingGoodsList();
            this.cblGoods.DataSource = dt;
            this.cblGoods.DataTextField = "GoodsName";
            this.cblGoods.DataValueField = "ID";
            this.cblGoods.DataBind();
        }
        else
        {
            dt = Wicresoft.Busi.BizLogic.BLMeetingRoomGoods.GetMeetingApplyGoods(this.ApplyID);
            this.cblGoods.DataSource = dt;
            this.cblGoods.DataTextField = "GoodsName";
            this.cblGoods.DataValueField = "GoodsID";
            this.cblGoods.DataBind();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["IsNeed"] != DBNull.Value && Convert.ToBoolean(dt.Rows[i]["IsNeed"]) != false)
                    cblGoods.Items[i].Selected = true;
            }
        }
    }
    #endregion

    #region 根据申请ID,读取申请详细信息
    private void LoadApplyInfo()
    {
        MeetingRoomApply info = new MeetingRoomApply(this.ApplyID);
        info.Load();
        if (info != null)
        {
            MeetingRooms room = new MeetingRooms(info.RoomID);
            room.Load();
            //ltRoomName.Text = room.RoomName;
            if (room.ID != int.MinValue)
            {
                if (UserType != "Approve")
                    this.ddlRoom.SelectedValue = room.ID.ToString();
            }

            ltHyrs.Text = info.PeopleCount.ToString();
            ltSbbm.Text = info.Sbbm;
            ltRemark4.Text = info.Remark4;
            ltTopic.Text = info.Topic;
            ltHysj.Text = info.MeetingDate.ToString("yyyy-MM-dd ") + info.StartTime + "至" + info.EndTime;
            ltHyhb.Text = info.Hb;
            ltHyc.Text = info.Hyc;
            ltZsp.Text = info.Zsp;
            ltXk.Text = info.Xk;
            ltRemark1.Text = info.Remark1;
            if (info.Remark2 == 1)
                cbImportance.Checked = true;
            else
                cbImportance.Checked = false;
            this.cbImportance.Enabled = false;

            this.ddlType.SelectedValue = info.Type.ToString();
            this.ddlType.Enabled = false;

            foreach (ListItem li in cblGoods.Items)
            {
                MeetingRoomApplyGoods oGoods = new MeetingRoomApplyGoods();
                oGoods.ApplyID = this.ApplyID;
                oGoods.GoodsID = int.Parse(li.Value);
                oGoods.Load("ApplyID='" + this.ApplyID + "' and GoodsID='" + oGoods.GoodsID + "'");
                li.Selected = oGoods.IsNeed;
            }
            cblGoods.Enabled = true;
            txtNote.Text = info.Notes;
            ltNote.Text = info.Notes;
            ltShyj.Text = info.Shyj;
            txtShyj.Text = info.Shyj;

            if (info.Status == Wicresoft.Busi.Entity.MeetingStatus.POST)
            {
                ltShyj.Visible = false;
                txtShyj.Visible = true;
               
                this.ddlRoom.Enabled = true;

            }
            else if (info.Status == Wicresoft.Busi.Entity.MeetingStatus.AUDIT)
            {
                

                if (string.IsNullOrEmpty(UserType))
                {
                  
                    this.ddlRoom.Enabled = true;
                }
            }
            else
            {
                
            }
            ApplyStatus = info.Status;
        }
    }
    #endregion
 
 
    #region 转换时间 ConvertToCover
    private int ConvertToCover(string StartTime, string EndTime)
    {
        int CoverTime = 0;
        if (DateTime.Parse(EndTime).Hour <= 12) CoverTime = 0;
        else if (DateTime.Parse(StartTime).Hour >= 12 && DateTime.Parse(EndTime).Hour <= 18) CoverTime = 1;
        else if (DateTime.Parse(StartTime).Hour >= 18) CoverTime = 3;
        else if (DateTime.Parse(StartTime).Hour <= 12 && DateTime.Parse(EndTime).Hour >= 12) CoverTime = 0;
        else if (DateTime.Parse(StartTime).Hour <= 18 && DateTime.Parse(EndTime).Hour >= 18) CoverTime = 1;
        return CoverTime;
    }
    #endregion
}
